<h1>Einkaufsartikel anlegen</h1>
<?php echo $this->getTplVar('msg'); ?>
<div class="addFormContainer" id="addArticle">
    <form action="./index.php?fnc=purchase&purchaseId=<?php echo $this->getTplVar('purchaseId'); ?>" method="post">
        <label>EAN</label><input type="text" name="ean" value="<?php echo $this->getTplVar('ean'); ?>" />
        <br />
        <label>Artikel</label>
        <select name="article_id">
            <option value="">Bitte Wählen</option>
            <?php
            $articleList = $this->getTplVar('listArticle');

            if (is_array($articleList)){
                foreach ($articleList AS $article){
                    $select = '';
                    if($article['id'] == $this->getTplVar('article_id')){
                        $select = 'selected="selected"';
                    }
                    echo  '<option value="'.$article['id'].'" '.$select.' >'.$article['name_de'].'</option>';
                }
            }
            ?>
        </select>
        <br />
        <label>Anbieter: </label><input type="text" name="supplier" value="<?php echo $this->getTplVar('supplier'); ?>" />
        <br />
        <label>Anzahl: </label><input type="text" name="count" value="<?php echo $this->getTplVar('count'); ?>" />
        <br />
        <label>Preis: </label><input type="text" name="price_e" value="<?php echo $this->getTplVar('price_e'); ?>" /><span> Euro</span>
        <br />

        <input type="hidden" name="action" value="addPurchaseArticle" />

        <input type="hidden" name="purchaseId" value="<?php echo $this->getTplVar('purchaseId'); ?>" />
        <label></label><input value="Anlegen" type="submit" />
    </form>

</div>
<h1>Gekaufte Artikeln</h1>
<div class="editFormContainer" id="editPurchaseArticle">
    <form action="./index.php?fnc=purchase&purchaseId=<?php echo $this->getTplVar('purchaseId'); ?>" method="post">

        <?php
        $length1 = 5;
        $length2 = 10;
        $length3 = 15;
        $length4 = 20;
        ?>

        <table class="purchaseArticleList">
            <tbody>
            <tr>
                <td width="<?php echo $length1; ?>%" valign="top">
                    <div>&nbsp;</div>
                </td>
                <td width="<?php echo $length3; ?>%" valign="top">
                    <div><strong>EAN</strong></div>
                </td>
                <td width="<?php echo $length3; ?>%" valign="top">
                    <div><strong>NAME(DE)</strong></div>
                </td>
                <td width="<?php echo $length3; ?>%" valign="top">
                    <div><strong>Name(CN)</strong></div>
                </td>
                <td width="<?php echo $length2; ?>%" valign="top">
                    <div><strong>Anbieter</strong></div>
                </td>
                <td width="<?php echo $length2; ?>%" valign="top">
                    <div><strong>Preis(Euro)</strong></div>
                </td>
                <td width="<?php echo $length1; ?>%" valign="top">
                    <div><strong>Anzahl</strong></div>
                </td>
                <td width="<?php echo $length2; ?>%" valign="top">
                    <div><strong>Gesamtpreis(Euro)</strong></div>
                </td>
            </tr>
            <?php
            $list = $this->getTplVar('einkauflist');
            if (is_array($list) && count($list) > 0){
                foreach ($list AS $item){

                    $name_cn = '---';
                    $name_de = '---';
                    if (!empty($item['name_cn'])){
                        $name_cn = $item['name_cn'];
                    }
                    if (!empty($item['name_de'])){
                        $name_cn = $item['name_de'];
                    }
                    echo '<tr>';

                    //check box <label for="'.$article['id'].'" class="selectBoxLabel">'.$article['name_de'].'</label></b>
                    echo '<td width="'.$length1.'%" valign="top"><div class="column"><input type="checkbox" name="purchaseArticleId[]" class="selectBox"  value="'.$item['id'].'" id="'.$item['id'].'"></div></td>';
                    echo '<td width="'.$length3.'%" valign="top"><div class="column">'.$item['ean'].'</div></td>';
                    echo '<td width="'.$length3.'%" valign="top"><div class="column">'.$item['name_de'].'</div></td>';
                    echo '<td width="'.$length3.'%" valign="top"><div class="column">'.$item['name_cn'].'</div></td>';
                    echo '<td width="'.$length2.'%" valign="top"><div class="column">'.$item['supplier'].'</div></td>';
                    echo '<td width="'.$length2.'%" valign="top"><div class="column">'.$item['price_e'].'</div></td>';
                    echo '<td width="'.$length1.'%" valign="top"><div class="column">'.$item['count'].'</div></td>';
                    echo '<td width="'.$length2.'%" valign="top"><div class="column">'.$item['total_price_e'].'</div></td>';
                    echo '</tr>';
                }
            }

            ?>
            </tbody>
        </table>

        <input type="submit" name="action" value="Löschen"/>
        <input type="submit" name="action" value="Export"  />

    </form>

</div>